package com.sss.otep.ws.endpoints;


import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;

import com.sss.otep.message.schemas.MemberPaidDeptRequest;
import com.sss.otep.message.schemas.MemberPaidDeptResponse;
import com.sss.otep.orm.model.MemberPaidDept;
import com.sss.otep.service.LoadParameter;
import com.sss.otep.service.OTEPService;
import com.sss.otep.util.SchemaConvertionUtils;

@Endpoint
public class CPKMemberPaidDeptEndPoint implements CPKEndpoint {
	private static final Logger log = LoggerFactory.getLogger(CPKMemberPaidDeptEndPoint.class);
	
	@Autowired
	private OTEPService service;
	
	@PayloadRoot(localPart="MemberPaidDeptRequest", namespace = NAMESPACE)
	public MemberPaidDeptResponse getMemberPaidDept(MemberPaidDeptRequest param){
		log.info("invoke member paid dept endpoint");
		LoadParameter loadParam = new LoadParameter();
		MemberPaidDeptResponse response = new MemberPaidDeptResponse();
		try{
			loadParam.setId(param.getId());			
			loadParam.setIdCard(param.getIdCard());
			loadParam.setName(param.getName());
			loadParam.setSurname(param.getSurname());
			
			List<MemberPaidDept> result = service.loadMemberPaidDept(loadParam);
			
			for(MemberPaidDept m : result){
				response.getMemberPaidDept().add(SchemaConvertionUtils.toSchema(m));
			}			
		}catch(Exception e){
			log.error("Member paid dept endpoint error occured !!",e);
		}
		
		return response;
	}
}
